package cn.stylefeng.guns.cp;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.guns.constant.Constant;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;

import java.util.*;

/**
 * @Description TODO
 * @Author xiesm
 * @Date 2024/3/11 10:59
 **/
@Data
public class Ssq {
    private String code1;
    private String code2;
    private String code3;
    private String code4;
    private String code5;
    private String code6;
    private String code7;
    private String issue;

    public Ssq(String code, String issue) {
        String[] codes = code.split(" ");
        this.code1 = codes[0];
        this.code2 = codes[1];
        this.code3 = codes[2];
        this.code4 = codes[3];
        this.code5 = codes[4];
        this.code6 = codes[5];
        this.code7 = codes[6];
        this.issue = issue;
    }

    public static String getMaxYilou(List<Ssq> ssqList) {
        CollUtil.reverse(ssqList);
        Map<String, Integer> result = new HashMap<>();
        for (int j = 1; j <= 16; j++) {
            String code = StrUtil.padPre(j + "", 2, "0");
            result.put(code, 0);
        }
        for (int i = 0; i < ssqList.size(); i++) {
            Ssq ssq = ssqList.get(i);
            String code7 = ssq.getCode7();
            Iterator<Map.Entry<String, Integer>> iterator = result.entrySet().iterator();
            while (iterator.hasNext()) {
                Map.Entry<String, Integer> next = iterator.next();
                if (next.getKey().equals(code7)) {
                    result.put(next.getKey(), 0);
                } else {
                    result.put(next.getKey(), next.getValue() + 1);
                }
            }
        }
        Iterator<Map.Entry<String, Integer>> iterator = result.entrySet().iterator();
        Integer max = 0;
        String maxCode = "";
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> next = iterator.next();
            if (next.getValue() > max) {
                max = next.getValue();
                maxCode = next.getKey();
            }
        }
        return maxCode;
    }
}
